package com.bj58.ecdata.dashboard.constant;

import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONArray;
import com.bj58.ecdata.dashboard.utils.DDateUtils;
import com.google.common.base.Joiner;


public class IncomeCateConst {

	private static Map<String, JSONArray> businessCateMap = new HashMap<String, JSONArray>();
	
	static{
		businessCateMap.put("zhaopin",JSONArray.parseArray("['销售','普工/技工','餐饮','人事/行政/后勤','客服','司机','物流/仓储','家政保洁/安保','美容/美发','淘宝职位','学生兼职','计算机/互联网/通信','娱乐/休闲','保健按摩','教育培训','美术/设计/创意','房产中介','服务员','礼仪/模特']"));
		businessCateMap.put("fangchan",JSONArray.parseArray("['租房','求租房','二手房','写字楼','商铺租售/生意转让','厂房/仓库/土地/车位','合租房']"));
		businessCateMap.put("huangye",JSONArray.parseArray("['搬家','租车','工商注册','投资担保','家装服务','家电维修','保洁清洗','保姆/月嫂','艺术培训','管道疏通','婚庆','餐饮加盟','开锁/换锁/修锁','电脑维修','房屋维修/防水','过户/验车','货运物流','摄影摄像','驾校']"));
		businessCateMap.put("ershou",JSONArray.parseArray("['二手手机','二手回收','宠物狗','二手家具','二手摩托车','台式机/配件','笔记本电脑','自行车/电动车','手机号码','办公用品/设备','二手设备','二手家电','服装/鞋帽/箱包','文体/户外/乐器','数码产品','平板电脑','艺术品/收藏品','宠物店/服务']"));
		businessCateMap.put("ershouchuangxin",JSONArray.parseArray("['二手设备','艺术品/收藏品','办公用品/设备','手机号码','成人用品','通讯业务','二手求购','校园二手','宠物狗','花鸟鱼虫','宠物赠送/领养','宠物猫','宠物用品/食品','宠物店/服务','二手回收']"));
		businessCateMap.put("ershoutuiguang",JSONArray.parseArray("['二手家具','笔记本电脑','自行车/电动车','二手摩托车','台式机/配件','二手手机','二手家电']"));
	}
	
	public static List<?> getCateListByBusiness(String businessName){
		return businessCateMap.get(businessName);
	}
	
	/**
	 * 类别三个产品线查询列，查询条件
	 * @param dateGroup
	 * @return
	 */
	public static String getCateProCol(String dateGroup){
		return dateGroup+",jingzhun_cash, jingzhun_user, zhiding_cash, zhiding_user, zhineng_cash, zhineng_user";
	}
	
	private static final String PATTEN_CatePro = "cate_name='%s' AND business_name='%s' AND stat_type='%s' GROUP BY %s";
	
	public static String getCateProCon(String dateGroup, String stat_type, String businessName, String cateName){
		return String.format(PATTEN_CatePro, cateName, businessName, stat_type, dateGroup);
	}
	
	/**
	 * 27个直销城市三个产品线 表格数据查询条件
	 * @param dateGroup
	 * @return
	 */
	private static final String CatePro_Table = "%s='%s' AND business_name='%s' AND stat_type='%s' GROUP BY cate_name";
	
	public static String getCateProTableCon(String dateGroup, String stat_type, String businessName, String dateVal){
		return String.format(CatePro_Table, dateGroup,dateVal, businessName, stat_type);
	}
	
	private static final String CON_CateCmp = "cate_name in('%s','%s') AND business_name='%s' AND stat_type='%s' GROUP BY cate_name,%s";
	private static final String COL_CateCmp = "%s,cate_name,%s_cash, %s_user";
	/**
	 * 城市对比查询列，查询条件
	 * @param dateGroup
	 * @return
	 */
	public static String getCateCmpCol(String dateGroup, String proType){
		return String.format(COL_CateCmp, dateGroup,proType,proType);
	}
	
	public static String getCateCmpCon(String dateGroup, String stat_type, String businessName, String Cate1,String Cate2){
		return String.format(CON_CateCmp, Cate1,Cate2, businessName, stat_type, dateGroup);
	}


	private static final String CON_CateConsume = "cate_name in('%s') AND business_name='%s'  AND stat_type='%s' GROUP BY cate_name,%s";
	private static final String COL_CateConsume = "%s,cate_name,%s, %s";
	/*
	 * 消耗周期
	 */
	public static String getCateConsumeCol(String dateGroup,String index1, String index2) {
		return String.format(COL_CateConsume,dateGroup,index1, index2);
	}

	public static String getCateConsumeCon(String businessName,String dateGroup, String stat_type, List<String> cateArr) {
		String CateString = Joiner.on("','").join(cateArr); //去掉 [ ]
		return String.format(CON_CateConsume,CateString,businessName,stat_type, dateGroup);
	}

	private static final String CON_CateConsumeTable = "business_name='%s' AND %s='%s' AND stat_type='%s'  GROUP BY cate_name";

	/*
	 * 消耗周期表格数据
	 */
	public static String getCateConsumeTableCon(String businessName,String dateGroup, String stat_type,String dateVal) {
		return String.format(CON_CateConsumeTable,businessName,dateGroup,stat_type, dateVal);
	}	
	

	private static final String CON_CateRadar = "cate_name in('%s') AND business_name='%s' AND stat_type='%s' AND is_vip='%s' GROUP BY cate_name,stat_date";
	
	public static String getCateRadarCon( String stat_type,String date, String businessName, List<String> cateArr,String is_vip) {
		StringBuilder sBuilder = new StringBuilder();
		String cateString = Joiner.on("','").join(cateArr); //去掉 [ ]
		
		sBuilder.append("stat_date>='");
		String beginDate = null;
		if("day".equals(stat_type)){
			beginDate = DDateUtils.varDate(date, "yyyy-MM-dd", Calendar.DATE, -11); //12个点
		}else if("week".equals(stat_type)){
			beginDate = DDateUtils.varDate(date, "yyyy-MM-dd", Calendar.DATE, -11*7);
		}
		sBuilder.append(beginDate +"' and  stat_date<='"+date+"' and ");
		return sBuilder + String.format(CON_CateRadar,cateString,businessName,stat_type,is_vip);

	}

	private static final String CON_CateRadar_Table = "stat_date='%s' AND business_name='%s' AND stat_type='%s' AND is_vip='%s' GROUP BY Cate_name";

	public static String getCateRadarTableCon(String stat_type, String dateVal, String businessName, String is_vip) {
		return String.format(CON_CateRadar_Table, dateVal, businessName, stat_type,is_vip);
	}
}
